import { _decorator, Component, Node,tween,Vec3,v3 } from 'cc';
import {AudioClipID, AudioManager} from "./AudioManager";
import {GameMain} from "./GameMain";
import Platform from "./Platform";
import {NativeEvt} from "./GameConfig";
const { ccclass, property } = _decorator;

@ccclass('GameOverUI')
export class GameOverUI extends Component {

    public targetNode:Node=null;
    public inited:boolean=false;

    onLoad()
    {
        this.init();
        Platform.createInsertAd();
    }

    start() {

    }

    public init()
    {
        if(this.inited)
            return;
        this.targetNode=this.node.getChildByName("window");
        this.inited=true;
    }

    public show()
    {
        if(this.node.active)
            return;

        this.init();
        this.node.active=true;
        this.targetNode.setScale(0.3, 0.3,1);
        tween(this.targetNode)
            .to(0.3,{scale:Vec3.ONE}, { easing: 'backOut' })
            .start();
    }

    public close()
    {
        tween(this.targetNode).to(0.2,{scale:v3(0.5, 0.5, 0.5)}).call(()=>{
            this.node.active=false;
        }).start();
    }

    public onCancel()
    {
        this.close();
        GameMain.instance.retryUI.show();
    }

    public onContinueClicked()
    {
        GameMain.instance.setVedioAwardScene(NativeEvt.VedioRelive);
        Platform.playVideoAd(() =>
        {
            this.videoAward();
        });
    }

    public videoAward()
    {
        GameMain.instance.mainUI.revive();
        this.close();
    }


    update(deltaTime: number) {
        
    }

}

